package com.ncp.servlet.index;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.index.NaviManager;
import com.ncp.model.biz.registerlogin.UserManager;
import com.ncp.model.entity.index.NaviBean;
import com.ncp.model.entity.registerlogin.UserBasicBean;

public class NaviClServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String type=request.getParameter("type");
		if(type.equals("addNavi")){
			String name=request.getParameter("name");
			String urlpage=request.getParameter("urlpage");
			boolean b=new NaviManager().addNavi(name,urlpage);
			if(b){
				response.sendRedirect("pages/admin/navilist.jsp");
			}
		}else if(type.equals("del")){
			String id=request.getParameter("id");
			boolean b=new NaviManager().delNavi(id);
			if(b){
				request.getRequestDispatcher("pages/admin/navilist.jsp").forward(request, response);
			}
		}else if(type.equals("update")){
			String id=request.getParameter("id");
			NaviBean nb=new NaviManager().getNavi(id);
			request.setAttribute("nb", nb);
			request.getRequestDispatcher("pages/admin/naviupdate.jsp").forward(request, response);
		}else if(type.equals("update1")){
			String id=request.getParameter("id");
			String name=request.getParameter("name");
			String urlpage=request.getParameter("urlpage");
			new NaviManager().updateNavi(id, name, urlpage);
			request.getRequestDispatcher("pages/admin/navilist.jsp").forward(request, response);
		}
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		this.doGet(request, response);
		
	}

}
